<template>
  <div class="u-p-20">
    <el-card shadow="never">
      <el-form :model="objForm" :rules="rules" ref="objForm" label-width="100px" class="u-form">
        <el-form-item label="选择商品">
          <el-input
            v-model="objForm.goods_id"
            placeholder="商品id"
            type="hidden"
            style="display: none;"
          ></el-input>
          <div v-if="objForm.goods_id!=''">
            <el-input v-model="objForm.goods_title" placeholder="商品标题" disabled></el-input>
          </div>
          <el-button type="text" @click="clickGoodsSelect()">选择商品</el-button>
        </el-form-item>
        <el-form-item label="商品数量">
          <el-input v-model="objForm.goods_storage" placeholder="商品数量"></el-input>
        </el-form-item>
      </el-form>
    </el-card>

    <!-- 商品弹出框 -->
    <el-dialog title="商品列表" :visible.sync="is_goods_show" width="65%" append-to-body>
      <Goods :isprops="true" @goods_select="goods_select" :agency="aid" ref="goodslist"></Goods>

      <span slot="footer" class="dialog-footer">
        <el-button @click="is_goods_show = false">取 消</el-button>
        <el-button type="primary" @click="is_goods_show = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import commonEdit from "@/mixins/common-edit";
import Goods from "@/views/goods/lists.vue";
export default {
  components: {
    Goods
  },
  props: {
    aid: {
      type: String
    }
  },
  mixins: [commonEdit],
  data() {
    return {
      apiName: "agencyGoods",
      objForm: {
        id: "",
        agency_id: "", //活动id
        goods_id: "", //商品id
        goods_storage: 0,
        status: 1
      },
      is_goods_show: false,
      resetInit: true
    };
  },
  methods: {
    goods_select(goods) {
      let goods_ids = goods.goods_id;
      if (goods_ids != "" && goods_ids != undefined) {
        this.objForm.id = "";
        this.objForm.agency_id = this.aid;
        this.objForm.goods_id = goods_ids.join(",");
           console.log(this.objForm.goods_id);
        this.objForm.goods_title = this.objForm.goods_id;
      }
      this.is_goods_show = false; //关闭弹框
    },
    submitEnd(code) {
      if (code == 1) {
        this.$emit("submit", {});
        this.objForm.goods_id = "";
        this.objForm.goods_title = "";
        this.objForm.goods_img = "";
        this.objForm.goods_storage = 0;
        this.objForm.status = 1;
      }
    },
    clickSub() {
      let self = this;
      self.submitForm("objForm");
    },
    clickGoodsSelect() {
      this.is_goods_show = true;
      let that = this;
      setTimeout(function() {
        that.$refs["goodslist"].upDateList();
      }, 500);
    }
  }
};
</script>
